// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   NoteAction.java

package com.iphaeton.lms.action.note;

import com.iphaeton.common.helper.Pagination;
import com.iphaeton.common.helper.UserSession;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.business.course.scorm12.ICourseService;
import com.iphaeton.lms.business.note.INoteService;
import com.iphaeton.lms.business.organize.IOrganizeService;
import com.iphaeton.lms.pojo.note.Note;
import com.iphaeton.lms.pojo.organize.Organize;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;

// Referenced classes of package com.iphaeton.lms.action.note:
//            NoteBizSupportAction

public class NoteAction extends NoteBizSupportAction
{

    public NoteAction()
    {
        cal = Calendar.getInstance();
        time = cal.getTime();
        df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        currentTime = df.format(time);
    }

    public ActionForward noteForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        java.util.List list;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String id = userSession.getId();
            list = note.findMyCourse(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("note_form");
    }

    public ActionForward createNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String reStr = "myNote";
        daf = (DynaActionForm)form;
        String title = (String)daf.get("title");
        String content = (String)daf.get("content");
        String course_id = (String)daf.get("course_id");
        Integer self = (Integer)daf.get("self");
        String type = request.getParameter("type");
        Note n = new Note();
        if(title != null && !"".equals(title))
            n.setTitle(title);
        n.setContent(content);
        n.setCourse_id(course_id);
        n.setCreate_time(currentTime);
        n.setSelf(self);
        n.setState(new Integer(2));
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String uid = userSession.getId();
            String user_id = userSession.getUserId();
            String user_name = userSession.getUserName();
            n.setCreate_id(uid);
            n.setCreate_userId(user_id);
            n.setCreate_name(user_name);
            n.setCourse(course.findCourseById(course_id));
            note.store(n);
            if(type.equals("play"))
            {
                reStr = "course_note";
                java.util.List list = course.findCourseNote(course_id, uid);
                request.setAttribute("courseId", course_id);
                request.setAttribute("list", list);
            }
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        return mapping.findForward(reStr);
    }

    public ActionForward updateNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String reStr = "myNote";
        daf = (DynaActionForm)form;
        String id = request.getParameter("id");
        String content = request.getParameter("content");
        Integer self = (Integer)daf.get("self");
        String type = request.getParameter("type");
        try
        {
            Note n = note.findNoteById(id);
            if(type.equals("play"))
            {
                reStr = "course_note";
                java.util.List list = course.findCourseNote(n.getCourse_id(), n.getCreate_id());
                request.setAttribute("courseId", n.getCourse_id());
                request.setAttribute("list", list);
            }
            n.setContent(content);
            n.setSelf(self);
            note.store(n);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        return mapping.findForward(reStr);
    }

    public ActionForward selectNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int pageSize = 10;
        int currentPage = 0;
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        if(strState == null)
            strState = "2";
        int state = Integer.parseInt(strState);
        java.util.List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String user_id = userSession.getId();
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = note.selectNote(user_id, null, row, state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = note.getSpecifiedNote(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("state", (new StringBuffer(String.valueOf(state))).toString());
        request.setAttribute("list", list);
        return mapping.findForward("my_note");
    }

    public ActionForward noteDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        Note n;
        try
        {
            n = note.findNoteById(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("note", n);
        return mapping.findForward("note_detail");
    }

    public ActionForward editNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        Note n;
        try
        {
            n = note.findNoteById(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("note", n);
        return mapping.findForward("note_edit");
    }

    public ActionForward soulNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        try
        {
            Note n = note.findNoteById(id);
            n.setState(new Integer(1));
            note.store(n);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        return mapping.findForward("noteList");
    }

    public ActionForward removeNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String type = request.getParameter("type");
        String reStr = "myNote";
        if(type.equals("list"))
            reStr = "noteList";
        String id = request.getParameter("id");
        try
        {
            note.remove(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("fialure");
        }
        return mapping.findForward(reStr);
    }

    public ActionForward noteList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int pageSize = 10;
        int currentPage = 0;
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        if(strState == null)
            strState = "2";
        int state = Integer.parseInt(strState);
        java.util.List list = null;
        try
        {
            UserSession userSession = (UserSession)request.getSession().getAttribute("userSession");
            String organize_id = userSession.getManageOrgId();
            String organize_url = organize.findOrganizeById(organize_id).getUrl();
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = note.getNoteList(organize_url, null, row, state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = note.getSpecifiedNote(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("state", (new StringBuffer(String.valueOf(state))).toString());
        request.setAttribute("list", list);
        return mapping.findForward("note_list");
    }

    public ActionForward courseNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int pageSize = 10;
        int currentPage = 0;
        String sortId = request.getParameter("sortId");
        String courseId = request.getParameter("courseId");
        if(sortId == null)
            sortId = "";
        if(courseId == null)
            courseId = "";
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        String strState = request.getParameter("state");
        if(strState == null)
            strState = "2";
        int state = Integer.parseInt(strState);
        java.util.List list = null;
        try
        {
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = note.findCourseNote(sortId, courseId, row, state, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = note.getSpecifiedNote(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("state", (new StringBuffer(String.valueOf(state))).toString());
        request.setAttribute("list", list);
        request.setAttribute("sort", sortId);
        request.setAttribute("course", courseId);
        return mapping.findForward("course_note_list");
    }

    public ActionForward courseSoulNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        int pageSize = 10;
        int currentPage = 0;
        String sortId = request.getParameter("sortId");
        String courseId = request.getParameter("courseId");
        if(sortId == null)
            sortId = "";
        if(courseId == null)
            courseId = "";
        String strPage = request.getParameter("page");
        String row = request.getParameter("row");
        java.util.List list = null;
        try
        {
            if(strPage == null || strPage.trim().equals(""))
                currentPage = 1;
            else
                currentPage = Integer.parseInt(strPage);
            pageInfo = note.findCourseNote(sortId, courseId, row, 1, pageSize);
            pageInfo.setPage(currentPage);
            pageInfo.setRow(row);
            request.getSession().setAttribute("pageInfo", pageInfo);
            list = note.getSpecifiedNote(pageInfo);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("list", list);
        request.setAttribute("sort", sortId);
        request.setAttribute("course", courseId);
        return mapping.findForward("soul_note");
    }

    private static Logger logger;
    private DynaActionForm daf;
    private Pagination pageInfo;
    Calendar cal;
    Date time;
    DateFormat df;
    String currentTime;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.note.NoteAction.class.getName());
    }
}
